﻿using MySql.Data.MySqlClient;
using newBlog.CenterInc.model;
using newBlog.inc.SqlINC;
using System.Collections.Generic;

namespace newBlog.CenterInc.Ctrltor
{
    public class catalog_inc
    {
        sqlConnect Conn = new sqlConnect();
        public List<catalog_Dao> Wrting()
        {
            List<catalog_Dao> list = new List<catalog_Dao>();
            string sql = "select Blog_catalog_id,Blog_catalog_name from blog_catalog";
            MySqlDataReader dr = Conn.DataListAll(sql);
            while (dr.Read())
            {
                catalog_Dao catalog_Dao = new catalog_Dao(dr.GetInt32(0), dr.GetString(1));
                list.Add(catalog_Dao);
            }
            return list;
        }//文章写作内的分类遍历

        public List<catalog_Dao> CatalogList() {
            List<catalog_Dao> list = new List<catalog_Dao>();
            string sql = "select Blog_catalog_id,Blog_catalog_name,Blog_catalog_content from blog_catalog";
            MySqlDataReader dr = Conn.DataListAll(sql);
            while (dr.Read())
            {
                catalog_Dao catalog_Dao = new catalog_Dao(dr.GetInt32(0), dr.GetString(1), dr.GetString(2));
                list.Add(catalog_Dao);
            }
            return list;
        }
        public int CatalogListCount() {
            string sql = "select count(Blog_catalog_id) from blog_catalog";
            return Conn.DataValue(sql);
        }
        public bool DelCatalog(string catalog_id) {
            string sql = "delete from blog_catalog where Blog_catalog_id='{0}'";
            if (Conn.AddDelUp(string.Format(sql, catalog_id)) < 1) {
                return true;
            }
            return false;
        }//删除分类
        public bool SelectCatalogArticle(string catalog_id)
        {
            string sql = "select count(Blog_article_id) from blog_article where Blog_catalog_id = '{0}'";
            if (Conn.DataValue(string.Format(sql, catalog_id)) >= 1) {
                return true;
            }
            return false;
        }

        public bool AddCatalog(string catalog_name,string catalog_content){
            string sql = "insert into blog_catalog(Blog_catalog_name,Blog_catalog_content) values('{0}','{1}')";
            if (Conn.AddDelUp(string.Format(sql,catalog_name,catalog_content))<1) {
                return true;
            }
            return false;
            }//添加分类
        public bool UpCatalog(string catalog_id,string catalog_name,string catalog_content) {
            string sql = "update blog_catalog set Blog_catalog_name='{0}',Blog_catalog_content='{1}' where Blog_catalog_id={2}";
            if (Conn.AddDelUp(string.Format(sql,catalog_name,catalog_content,catalog_id))<1) {
                return true;
            }
            return false;
        }//修改分类
    }
}